/**
 * 
 */
package com.example.queue.dao;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.example.queue.dto.EmployeeBean;
import com.example.queue.util.JMSUtil;

/**
 * @author sunaina.sharma
 * 
 */
@Repository
public class EmployeeDAOImpl implements EmployeeDAO {

	@Autowired
	SessionFactory sessionFactory;

	/*
	 * This method will add employee details in database (non-Javadoc)
	 * 
	 * @see
	 * com.example.queue.dao.EmployeeDAO#addEmployeeDetails(com.example.queue
	 * .dto.EmployeeBean)
	 */
	@Override
	public void addEmployeeDetails(EmployeeBean employeeBean) throws Exception {
		try {
			Session session = sessionFactory.getCurrentSession();
			Transaction transaction = session.beginTransaction();
			session.save(employeeBean);
			transaction.commit();
			// session.close();

			JMSUtil.startJMServer();
			JMSUtil.sendMessage();
		} catch (HibernateException hibernateException) {
			throw hibernateException;
		} catch (SQLException sqlException) {
			throw sqlException;
		} catch (Exception exception) {
			throw exception;
		} finally {
			JMSUtil.stopJMServer();
		}
	}
}
